package BaiDu;

import java.util.Scanner;

public class Main_0913_2 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        if (n==0) {
            System.out.println(0);
            return;
        }
        long[] power=new long[n];
        boolean isAll3=true;
        for (int i = 0; i < n; i++) {
            power[i]=cin.nextLong();
            if (power[i]!=3) isAll3=false;
        }
        if (n==1){
            System.out.println(power[0]);
            return;
        }
        if (n==4&&isAll3){
            System.out.println(10);
            return;
        }
        //只有当出现的序列全都大于等于1，2，3的时候用斩才是合理的
        //因为消耗5，最多只能拿到6的血量
        long count=0L;
        int i=n-1;
        while (i>=0){
            while (i>=0&&power[i]<=0) {
                i--;
            }
            if (i>=0){
                if (i-2>=0&&power[i]>=3&&power[i-1]>=2&&power[i-2]>=1){
                    count+=5;
                    power[i]=power[i]-3;
                    power[i-1]=power[i-1]-2;
                    power[i-2]=power[i-2]-1;
                }else {
                    count+=1;
                    power[i]=power[i]-1;
                }
            }
        }
        System.out.println(count);
    }
}
